package 纯数组;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class NC61两数之和 {

    /**
     * 力扣第一题
     */

    public int[] twoSum (int[] numbers, int target) {

        Map<Integer,Integer> map=new HashMap<>();

        //应该在遍历途中就进行target检测,这样又快又不会被重复元素干扰

        for (int i = 0; i < numbers.length; i++) {
            if(map.get(target-numbers[i])!=null){
                return new int[]{map.get(target-numbers[i])+1,i+1};
            }
            map.put(numbers[i],i);
        }

        return new int[]{-1,-1};
    }

}
